﻿@page
@model ToolGood.FlowVision.Pages.Members.SubAccounts.ChangePasswordModel
@{
    Layout = "~/Pages/Shared/_Layout_Edit.cshtml";
}
<form id="edit-form">
    @Html.AntiForgeryToken()
    <div id="hidden" class="hidden" style="display:none;width:0;height:0;">
        <input type="text" name="username" id="username" value="test" autocomplete="on" maxlength="20" required="" placeholder="请输入用户名" style="display:none" />
        <input type="password" name="password" id="password" value="fuckAutocomplete" autocomplete="on" maxlength="20" required="" placeholder="请输入密码" style="display:none" />
    </div>
    <div class="layui-form layui-form-sm" style="padding: 20px 30px 0 0;">
        <div class="layui-form-item-sm">
            <label class="layui-form-label-sm">账号 </label>
            <div class="layui-input-block-sm">
                <input type="text" value="@Model.Admin.Name" autocomplete="off" disabled readonly class="layui-input layui-input-sm layui-disabled">
            </div>
        </div>
        <div class="layui-form-item-sm">
            <label class="layui-form-label-sm">新密码 <span class="red">*</span></label>
            <div class="layui-input-block-sm">
                <input type="password" name="NewPassword" id="NewPassword" autocomplete="off" class="layui-input layui-input-sm">
            </div>
        </div>

        <div class="layui-form-item-sm">
            <label class="layui-form-label-sm">确认密码 <span class="red">*</span></label>
            <div class="layui-input-block-sm">
                <input type="password" name="ConfirmPassword" id="ConfirmPassword" autocomplete="off" class="layui-input layui-input-sm">
            </div>
        </div>
        <hr />
        <hr />
        <div class="layui-form-item-sm">
            <label class="layui-form-label-sm">管理员密码 <span class="red">*</span></label>
            <div class="layui-input-block-sm">
                <input type="password" placeholder="管理员密码" name="OldPassword" id="OldPassword" autocomplete="off" class="layui-input layui-input-sm">
            </div>
        </div>
        <div class="layui-form-item-sm">
            <div style="text-align:center;">
                <button type="button" class="layui-btn layui-btn-normal" onclick="save(this)"> 保 存 </button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="closeWindow()"> 关 闭 </button>
            </div>
        </div>
    </div>
</form>
@section js{
        <script>
            $(function () {
                $("input#NewPassword").keyup(function (key) { if (key.keyCode == 13) { $("input#ConfirmPassword").focus(); } });
                $("input#ConfirmPassword").keyup(function (key) { if (key.keyCode == 13) { $("input#OldPassword").focus(); } });
                $("input#OldPassword").keyup(function (key) { if (key.keyCode == 13) { save(); } });
            });
            function save(obj) {
                var NewPassword = $("#NewPassword").val();
                var ConfirmPassword = $("#ConfirmPassword").val();
                var OldPassword = $("#OldPassword").val();
                if (NewPassword.length < 3) { layer.msg("请输入新密码。"); return; }
                if (ConfirmPassword.length < 3) { layer.msg("请输入确认密码。"); return; }
                if (NewPassword != ConfirmPassword) { layer.msg("请核对新密码。"); return; }
                if (OldPassword.length < 3) { layer.msg("请输入密码。"); return; }

                $(obj).prop("disabled", true);
                var url = "./Ajax/ChangePassword";
                var data = {
                    data: $("#edit-form").serializeJson(),
                    fingerprint: window.fingerprint
                }
                $.ajax({
                    type: "POST",
                    url: url,
                    contentType: "application/json;charset=UTF-8",
                    data: JSON.stringify(data),
                    headers: { __RequestVerificationToken: data.data["__RequestVerificationToken"] },
                    dataType: "JSON",
                    success: function (data, textStatus, jqXHR) {
                        if (data.state == "SUCCESS") {
                            closeWindowAndReload();
                        } else {
                            $(obj).prop("disabled", false);
                            if (data.message) {
                                layer.msg(data.message);
                            } else {
                                layer.msg("出错了");
                            }
                        }
                    },
                    error: function (data, textStatus, errorThrown) { $(obj).prop("disabled", false); layer.msg("出错了"); }
                });
            }
        </script>
}